import { _decorator, Component, Node } from 'cc';
import { UILoading } from './UILoading';
import { BundleCallback, BundleLoadedCallback, BundlesCallback, ErrorCallback } from '../../../../sgame/resource/ResLoader';
import { ILoadinOption } from '../../../../sgame/ui/SUI';
const { ccclass, property } = _decorator;

@ccclass('UILoadingLayer')
export class UILoadingLayer extends Component {
    @property(Node)
    public loadingNode: Node;

    public loading(bundle: string | string[] | ILoadinOption, onComplete?: BundlesCallback, onCompleteOne?: BundleCallback, onError?: ErrorCallback) {
        if (typeof bundle !== "string" && !(bundle instanceof Array)) {
            onError = bundle.onError;
            onCompleteOne = bundle.onCompleteOne;
            onComplete = bundle.onComplete;
            bundle = bundle.bundle;
        }

        this.loadingNode.getComponent(UILoading).loading(bundle, onComplete, onCompleteOne, onError);
    }

    public stop() {
        this.loadingNode.getComponent(UILoading).startLoading();
    }
}